package com.cskaoyan.controller;

import com.cskaoyan.bean.market.Region;
import com.cskaoyan.bean.wxfree.WxFeedback;
import com.cskaoyan.bo.wxfree.WxFbSubmitBo;
import com.cskaoyan.bo.wxfree.WxFpDeleteBo;
import com.cskaoyan.service.wxfree.*;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.vo.wxfree.WxCommentCount;
import com.cskaoyan.vo.wxfree.WxCommentListVo;
import com.cskaoyan.vo.wxfree.WxFootprintListVo;
import com.cskaoyan.vo.wxfree.WxSearchIndexVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: mall
 * @description:
 * @author: Mr.Mengmeng
 * @create: 2021-04-11 23:21
 **/
// wx小程序 闲杂模块
@RestController
public class WxFreeController {



    // 搜索模块
    @RestController
    @RequestMapping("wx/search")
    public class SearchController {

        @Autowired
        WxSearchService wxSearchService;
        // wx/search/index
        @GetMapping("index")
        public BaseRespVo searchIndex() {
            WxSearchIndexVo vo = wxSearchService.searchIndex();
            return BaseRespVo.ok(vo);
        }
        // wx/search/helper?keyword=%E6%88%91
        // wx/search/helper?keyword=w
        @GetMapping("helper")
        public BaseRespVo searchHelper(String keyword) {
//            String[] strings = wxSearchService.searchHelper(keyword);
            List<String> strings = wxSearchService.searchHelper(keyword);
            return BaseRespVo.ok(strings);
        }
        // wx/search/clearhistory
        @PostMapping("clearhistory")
        public BaseRespVo searchClearHistory() {
            wxSearchService.searchClearHistory();
            return BaseRespVo.ok();
        }
    }

    // 评论模块
    @RestController
    @RequestMapping("wx/comment")
    public class CommentController {
        @Autowired
        WxCommentService wxCommentService;

        // wx/comment/list?valueId=1181000&type=0&size=20&page=1&showType=0
        @GetMapping("list")
        public BaseRespVo commentList(Integer valueId,Byte type,Integer size,Integer page,Boolean showType) {
            WxCommentListVo wxCommentListVo = wxCommentService.commentList(valueId, type, size, page, showType);
            return BaseRespVo.ok(wxCommentListVo);
        }
        // wx/comment/count?valueId=1181000&type=0
        @GetMapping("count")
        public BaseRespVo commentCount(Integer valueId,Byte type) {
            WxCommentCount wxCommentCount = wxCommentService.commentCount(valueId, type);
            return BaseRespVo.ok(wxCommentCount);
        }
    }

    // 地址模块
    @RestController
    @RequestMapping("wx/region")
    public class RegionController {
        @Autowired
        WxRegionService wxRegionService;

        // wx/region/list?pid=0
        @GetMapping("list")
        public BaseRespVo regionList(Integer pid) {
            List<Region> regions = wxRegionService.regionList(pid);
            return BaseRespVo.ok(regions);
        }
    }

    // 反馈模块
    @RestController
    @RequestMapping("wx/feedback")
    public class FeebbackController {

        @Autowired
        WxFeedbackService wxFeedbackService;

        // wx/feedback/submit
        @PostMapping("submit")
        public BaseRespVo fbSubmit(@RequestBody WxFbSubmitBo wxFbSubmitBo) {
            WxFeedback wxFeedback = wxFeedbackService.fbSubmit(wxFbSubmitBo);
            return BaseRespVo.ok(wxFeedback);
        }
    }

    // 足迹模块
    @RestController
    @RequestMapping("wx/footprint")
    public class FootprintController {
        @Autowired
        WxFootprintService wxFootprintService;

        // wx/footprint/list?page=1&size=10
        @GetMapping("list")
        public BaseRespVo fpList(Integer page,Integer size) {
            WxFootprintListVo vo = wxFootprintService.fpList(page, size);
            return BaseRespVo.ok(vo);
        }
        // wx/footprint/delete
        @PostMapping("delete")

        public BaseRespVo fpDelete(@RequestBody WxFpDeleteBo bo) {
            wxFootprintService.fpDelete(bo);
            return BaseRespVo.error(0,"成功");
        }
    }


}
